package com.carleasoft.mps.cms.business.education.controller;

import com.carleasoft.mps.cms.business.education.bean.entity.EducationEntity;
import com.carleasoft.mps.cms.business.education.bean.vo.EducationTreeVo;
import com.carleasoft.mps.cms.business.education.service.EducationService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 教育资源库
 *
 * @author: yangHao
 * @createDate:2023/6/6
 * @description:
 */
@RestController
@RequestMapping("/education")
public class EducationController {

    @Autowired
    private EducationService educationService;

    /**
     * 添加/编辑 所属库
     *
     * @param educationEntity
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody EducationEntity educationEntity) {
        boolean isOk = educationService.saveEducation(educationEntity);
        return R.ok(isOk);
    }

    /**
     * 查询所属库集合
     *
     * @param
     * @return
     */
    @PostMapping("/select")
    public R select() {
        List<EducationEntity> educationEntities = educationService.select();
        return R.ok(educationEntities);
    }

    /**
     * 删除
     *
     * @param educationEntity
     * @return
     */
    @PostMapping("/delete")
    public R delete(@RequestBody EducationEntity educationEntity) {
        IBeanUtil.paramVerify(educationEntity, "educationCode");
        boolean isOk = educationService.delete(educationEntity);
        return R.ok(isOk);
    }


    /**
     * 查询资源库树
     * @return
     */
    @PostMapping("/getTree")
    public R getTree() {
        List<EducationTreeVo> educationTreeVos = educationService.getTree();
        return R.ok(educationTreeVos);
    }

}
